/*****************************************************************
**                                                             	**
**  Copyright (C) 2004 Amlogic,Inc.                            	**
**  All rights reserved                                        	**
**        Filename : FileTypeSelect.c /Project:AVOS		       **
**        Revision : 1.1                                       	**
**                                                             	**
*****************************************************************/
#include "../menu.h"
#include "FileTypeSelectEvent.h"
#include "NetmenuSetupEvent.h"

INT32S WinFileTypeSelectMsgProc(PHWND hwnd, INT32U msg_type, INT32S lpParam)
{
    switch( msg_type){
        case WM_SHOWWINDOW:
            return WinFileTypeSelectOnShow(hwnd, lpParam) ;
    }
    return 0 ;
}

void SetWinFileTypeSelectPalette(void)
{
    YUVENTRY mask_para[4] = {0,0,0,4095};
    AWSetAlphaMask(0,4, mask_para);
    YUVENTRY palette_para[16] = {0x8000 | 16392,0x8000 | 21176,0x8000 | 17752,0x8000 | 16392,17592,19496,19832,19656,19992,18104,17673,17817,15864,15721,15912,16344};
    AWSetPalette(0,16, palette_para);
    return ;
}

void SetWinFileTypeSelectPos(HWND* pControl, INT8U CurOsdSize)
{
    switch(CurOsdSize){
	case OsdSize576i:
	case OsdSize576p:
	case OsdSize480i:
	case OsdSize480p:
	case OsdSize480iCVBS:
	case OsdSize576iCVBS:
    #ifdef SUPPORT_VGA
	case OsdSizeVga:
    #endif
            RECT NormalWindowRect = {0,0,720,576};
            pControl->winrect = NormalWindowRect;
            CREATEWINDOWPARAM NormalWindowPara = {1,{{0,0,720,576},    {0,0,0,0},{0,0,0,0},{0,0,0,0}},{PF_PALETTE_256,0,0,0},    SetWinFileTypeSelectPalette};
            AWSendMessage(pControl, WM_WINDOW_RESET_DRAW_AREA, (INT32S)&NormalWindowPara);
            break ;
    }//end of switch
    return;
}

HWND *CreateControlWinFileTypeSelect(HWND* pParent,INT8U CurOsdSize)
{
    HWND* pNewControl;
    switch(CurOsdSize){
	case OsdSize576i:
	case OsdSize576p:
	case OsdSize480i:
	case OsdSize480p:
	case OsdSize480iCVBS:
	case OsdSize576iCVBS:
    #ifdef SUPPORT_VGA
	case OsdSizeVga:
    #endif
            CREATEWINDOWPARAM Normalwindow_para = {1,{{0,0,720,576},{0,0,0,0},{0,0,0,0},{0,0,0,0}},{PF_PALETTE_256,0,0,0},SetWinFileTypeSelectPalette};
            //Create Menu Window -- 1
            pNewControl = AWCreateWinControl("TWindow","WinFileTypeSelect",WS_OVERLAPPEDWINDOW,
		                      0,0,720,576,NULL, (INT32S)&Normalwindow_para,WinFileTypeSelectMsgProc) ;
            pNewControl->win_id = 0 ;
            break ;
    }//end of switch
            return pNewControl;
}

INT32S WinFileTypeSelectInfoMsgProc(PHWND hwnd, INT32U msg_type, INT32S lpParam)
{
    switch( msg_type){
        case WM_SHOWWINDOW:
            return WinFileTypeSelectInfoOnShow(hwnd, lpParam) ;
        case WM_KEYDOWN:
            return WinFileTypeSelectInfoOnKeyPress(hwnd, lpParam) ;
    }
    return 0 ;
}

#ifdef TXT_PLAYER

  void SetWinFileTypeSelectInfoPos(HWND *pControl, INT8U CurOsdSize)
  {
    int iLoop;
    switch (CurOsdSize)
    {
      case OsdSize576i:
      case OsdSize576p:
      case OsdSize576iCVBS:
        pControl->winrect.top = pControl->parent->winrect.top + 48;
        pControl->winrect.left = pControl->parent->winrect.left + 0;
        pControl->winrect.width = 720;
        pControl->winrect.height = 480;
        pControl->draw_info_num = 15;
        RECT DrawRect576i[15] = 
        {
          {pControl->winrect.left + 85, pControl->winrect.top + 218, 110, 118},
          {pControl->winrect.left + 195, pControl->winrect.top + 218, 110, 118},
          {pControl->winrect.left + 305, pControl->winrect.top + 218, 110, 118},
          {pControl->winrect.left + 415, pControl->winrect.top + 218, 110, 118},
          {pControl->winrect.left + 525, pControl->winrect.top + 218, 110, 118},
          
          {pControl->winrect.left + 85, pControl->winrect.top + 368, 110, 30},
          {pControl->winrect.left + 195, pControl->winrect.top + 368, 110, 30},
          {pControl->winrect.left + 305, pControl->winrect.top + 368, 110, 30},
          {pControl->winrect.left + 415, pControl->winrect.top + 368, 110, 30},
          {pControl->winrect.left + 525, pControl->winrect.top + 368, 110, 30},
          
          {pControl->winrect.left + 115, pControl->winrect.top + 306, 110, 30},
          {pControl->winrect.left + 225, pControl->winrect.top + 306, 110, 30}, 
          {pControl->winrect.left + 335, pControl->winrect.top + 306, 110, 30}, 
          {pControl->winrect.left + 445, pControl->winrect.top + 306, 110, 30}, 
          {pControl->winrect.left + 555, pControl->winrect.top + 306, 110, 30},                      
        }
        ;
        for (iLoop = 0; iLoop < 15; iLoop++)
          memcpy(&(pControl->draw_info[iLoop]), &DrawRect576i[iLoop], sizeof(RECT));          
        break;

      case OsdSize480i:
      case OsdSize480p:
      case OsdSize480iCVBS:
        #ifdef SUPPORT_VGA
        case OsdSizeVga:
        #endif 
        pControl->winrect.top = pControl->parent->winrect.top + 0;
        pControl->winrect.left = pControl->parent->winrect.left + 0;
        pControl->winrect.width = 720;
        pControl->winrect.height = 480;
        pControl->draw_info_num = 15;
        RECT NormalDrawRect[15] = 
        {
          {pControl->winrect.left + 85, pControl->winrect.top + 218, 110, 118}, 
          {pControl->winrect.left + 195, pControl->winrect.top + 218, 110, 118},
          {pControl->winrect.left + 305, pControl->winrect.top + 218, 110, 118},
          {pControl->winrect.left + 415, pControl->winrect.top + 218, 110, 118},
          {pControl->winrect.left + 525, pControl->winrect.top + 218, 110, 118},

          {pControl->winrect.left + 85, pControl->winrect.top + 368, 110, 30}, 
          {pControl->winrect.left + 195, pControl->winrect.top + 368, 110, 30}, 
          {pControl->winrect.left + 305, pControl->winrect.top + 368, 110, 30},
          {pControl->winrect.left + 415, pControl->winrect.top + 368, 110, 30},
          {pControl->winrect.left + 525, pControl->winrect.top + 368, 110, 30},

          {pControl->winrect.left + 115, pControl->winrect.top + 306, 110, 30}, 
          {pControl->winrect.left + 225, pControl->winrect.top + 306, 110, 30}, 
          {pControl->winrect.left + 335, pControl->winrect.top + 306, 110, 30},
          {pControl->winrect.left + 445, pControl->winrect.top + 306, 110, 30},
          {pControl->winrect.left + 555, pControl->winrect.top + 306, 110, 30},
        };       
        for (iLoop = 0; iLoop < 15; iLoop++)
          memcpy(&(pControl->draw_info[iLoop]), &NormalDrawRect[iLoop], sizeof
            (RECT));
        break;
    } //end of switch
    return ;
  }



  HWND *CreateControlWinFileTypeSelectInfo(HWND *pParent, INT8U CurOsdSize)
  {
    //Create Control -- WinFileTypeSelectInfo
    HWND *pNewControl;
    switch (CurOsdSize)
    {
      case OsdSize576i:
      case OsdSize576p:
      case OsdSize576iCVBS:
      case OsdSize480i:
      case OsdSize480p:
      case OsdSize480iCVBS:
        #ifdef SUPPORT_VGA
        case OsdSizeVga:
        #endif 
        pNewControl = AWCreateWinControl("TControl", "WinFileTypeSelectInfo", 
          (WS_CHILDWINDOW | WS_CHILDWINDOW), 0, 0, 720, 480, pParent, 0,
          WinFileTypeSelectInfoMsgProc);
        pNewControl->win_id = 1;
        pNewControl->draw_info_num = 15;
        pNewControl->draw_info = (PDRAWINFO)AVMem_umalloc(sizeof(DRAWINFO)
          *pNewControl->draw_info_num);
        DRAWINFO NormalDrawDatas[15] = 
        {
          {0, 0, 0, 0, (INT32U)ICON_MOVIE_FOCUS, DT_RLE_BMP_DATA}, 
          {0, 0, 0, 0, (INT32U)ICON_MUSIC_LOSE, DT_RLE_BMP_DATA},
          {0, 0, 0, 0, (INT32U)ICON_PHOTO_LOSE, DT_RLE_BMP_DATA}, 
          {0, 0, 0, 0, (INT32U)ICON_TXT_LOSE, DT_RLE_BMP_DATA}, 
          {0, 0, 0, 0, (INT32U)ICON_FILE_LOSE, DT_RLE_BMP_DATA},

          {0, 0, 0, 0, (INT32U)0, DT_RLE_BMP_DATA},
          {0, 0, 0, 0, (INT32U)0, DT_RLE_BMP_DATA},
          {0, 0, 0, 0, (INT32U)0, DT_RLE_BMP_DATA},
          {0, 0, 0, 0, (INT32U)0, DT_RLE_BMP_DATA}, 
          {0, 0, 0, 0, (INT32U)0, DT_RLE_BMP_DATA},
            
          {0, 0, 0, 0, (INT32U)0, DT_RESOURCE_STRING_DATA}, 
          {0, 0, 0, 0, (INT32U)0, DT_RESOURCE_STRING_DATA},
          {0, 0, 0, 0, (INT32U)0, DT_RESOURCE_STRING_DATA},
          {0, 0, 0, 0, (INT32U)0, DT_RESOURCE_STRING_DATA},
          {0, 0, 0, 0, (INT32U)0, DT_RESOURCE_STRING_DATA},
        };
        
        memcpy(pNewControl->draw_info, NormalDrawDatas, sizeof(DRAWINFO)*pNewControl->draw_info_num);          
        break;
    } //end of switch
    return pNewControl;
  }


#else 

void SetWinFileTypeSelectInfoPos(HWND* pControl, INT8U CurOsdSize)
{
    int iLoop;
    switch(CurOsdSize){
	case OsdSize576i:
	case OsdSize576p:
	case OsdSize576iCVBS:
            pControl->winrect.top = pControl->parent->winrect.top + 48;
            pControl->winrect.left = pControl->parent->winrect.left + 0;
            pControl->winrect.width = 720;
            pControl->winrect.height = 480;
            pControl->draw_info_num = 12;
            RECT DrawRect576i[12] = {
            {pControl->winrect.left + 140,pControl->winrect.top + 218,110,118},
            {pControl->winrect.left + 250,pControl->winrect.top + 218,110,118},
            {pControl->winrect.left + 360,pControl->winrect.top + 218,110,118},
            {pControl->winrect.left + 470,pControl->winrect.top + 218,110,118},
            {pControl->winrect.left + 140,pControl->winrect.top + 368,110,30},
            {pControl->winrect.left + 250,pControl->winrect.top + 368,110,30},
            {pControl->winrect.left + 360,pControl->winrect.top + 368,110,30},
            {pControl->winrect.left + 470,pControl->winrect.top + 368,110,30},
            {pControl->winrect.left + 170,pControl->winrect.top + 306,110,30},
            {pControl->winrect.left + 280,pControl->winrect.top + 306,110,30},
            {pControl->winrect.left + 390,pControl->winrect.top + 306,110,30},
            {pControl->winrect.left + 500,pControl->winrect.top + 306,110,30},
            };
            for(iLoop=0; iLoop < 12; iLoop++)
                memcpy(&(pControl->draw_info[iLoop]), &DrawRect576i[iLoop], sizeof(RECT));
            break ;
		
	case OsdSize480i:
	case OsdSize480p:
	case OsdSize480iCVBS:
    #ifdef SUPPORT_VGA
	case OsdSizeVga:
    #endif
            pControl->winrect.top = pControl->parent->winrect.top + 0;
            pControl->winrect.left = pControl->parent->winrect.left + 0;
            pControl->winrect.width = 720;
            pControl->winrect.height = 480;
            pControl->draw_info_num = 12;
            RECT NormalDrawRect[12] = {
            {pControl->winrect.left + 140,pControl->winrect.top + 218,110,118},
            {pControl->winrect.left + 250,pControl->winrect.top + 218,110,118},
            {pControl->winrect.left + 360,pControl->winrect.top + 218,110,118},
            {pControl->winrect.left + 470,pControl->winrect.top + 218,110,118},
            {pControl->winrect.left + 140,pControl->winrect.top + 338,110,30},
            {pControl->winrect.left + 250,pControl->winrect.top + 338,110,30},
            {pControl->winrect.left + 360,pControl->winrect.top + 338,110,30},
            {pControl->winrect.left + 470,pControl->winrect.top + 338,110,30},
            {pControl->winrect.left + 170,pControl->winrect.top + 306,110,30},
            {pControl->winrect.left + 280,pControl->winrect.top + 306,110,30},
            {pControl->winrect.left + 390,pControl->winrect.top + 306,110,30},
            {pControl->winrect.left + 500,pControl->winrect.top + 306,110,30},
            };
            for(iLoop=0; iLoop < 12; iLoop++)
                memcpy(&(pControl->draw_info[iLoop]), &NormalDrawRect[iLoop], sizeof(RECT));
            break ;
    }//end of switch
    return;
}
HWND *CreateControlWinFileTypeSelectInfo(HWND *pParent,INT8U CurOsdSize)
{
    //Create Control -- WinFileTypeSelectInfo
    HWND *pNewControl;
    switch(CurOsdSize){
	case OsdSize576i:
	case OsdSize576p:
	case OsdSize576iCVBS:
	case OsdSize480i:
	case OsdSize480p:
	case OsdSize480iCVBS:
    #ifdef SUPPORT_VGA
	case OsdSizeVga:
    #endif
            pNewControl = AWCreateWinControl("TControl","WinFileTypeSelectInfo",(WS_CHILDWINDOW | WS_CHILDWINDOW),
		                      0,0,720,480,pParent,0,WinFileTypeSelectInfoMsgProc) ;
            pNewControl->win_id = 1 ;
            pNewControl->draw_info_num = 12;
            pNewControl->draw_info = (PDRAWINFO)AVMem_umalloc(sizeof(DRAWINFO) * pNewControl->draw_info_num) ;
            DRAWINFO NormalDrawDatas[12] = {
                          {0,0,0,0,(INT32U)ICON_MOVIE_FOCUS,DT_RLE_BMP_DATA},
                          {0,0,0,0,(INT32U)ICON_MUSIC_LOSE,DT_RLE_BMP_DATA},
                          {0,0,0,0,(INT32U)ICON_PHOTO_LOSE,DT_RLE_BMP_DATA},
                          {0,0,0,0,(INT32U)ICON_FILE_LOSE,DT_RLE_BMP_DATA},
                          {0,0,0,0,(INT32U)0,DT_RLE_BMP_DATA},
                          {0,0,0,0,(INT32U)0,DT_RLE_BMP_DATA},
                          {0,0,0,0,(INT32U)0,DT_RLE_BMP_DATA},
                          {0,0,0,0,(INT32U)0,DT_RLE_BMP_DATA},
                          {0,0,0,0,(INT32U)0,DT_RESOURCE_STRING_DATA},
                          {0,0,0,0,(INT32U)0,DT_RESOURCE_STRING_DATA},
                          {0,0,0,0,(INT32U)0,DT_RESOURCE_STRING_DATA},
                          {0,0,0,0,(INT32U)0,DT_RESOURCE_STRING_DATA}};
            memcpy(pNewControl->draw_info,NormalDrawDatas, sizeof(DRAWINFO) * pNewControl->draw_info_num) ;
            break ;
    }//end of switch
            return pNewControl;
}
#endif




HWND* CreateMenuWinFileTypeSelect(void)
{
    HWND *pNewControl ;
    TWINDOWS *pWin;
    HWND *pWinFileTypeSelect = CreateControlWinFileTypeSelect(NULL,CurrentOsdSize);
    SetWinFileTypeSelectPos(pWinFileTypeSelect,CurrentOsdSize);

    pNewControl= CreateControlWinFileTypeSelectInfo(pWinFileTypeSelect,CurrentOsdSize);
    SetWinFileTypeSelectInfoPos(pNewControl,CurrentOsdSize);

    pWin = (TWINDOWS *)pWinFileTypeSelect;
    pWin->pFocusControl = AWFindWinCtrlByName("WinFileTypeSelectInfo");
    return pWinFileTypeSelect;
}

void WinResetWinFileTypeSelectControlsPos(HWND *pControl, INT8U CurOsdSize)
{
    switch(pControl->win_id){
        case 0://WinFileTypeSelect
            SetWinFileTypeSelectPos(pControl,CurOsdSize) ;
            break ;
        case 1://WinFileTypeSelectInfo
            SetWinFileTypeSelectInfoPos(pControl,CurOsdSize) ;
            break ;
    }//end of switch
}
void WinResetWinFileTypeSelectPos(HWND *pControl, INT8U CurOsdSize)
{
    HWND *pChildControl;
    if(pControl == NULL)
        pControl = AWFindWinCtrlByName("WinFileTypeSelect");
    if(pControl == NULL) return ;

    WinResetWinFileTypeSelectControlsPos(pControl, CurOsdSize) ;
    pChildControl = pControl->children ;
    while(pChildControl != NULL){
    	WinResetWinFileTypeSelectPos(pChildControl, CurOsdSize) ;
    	pChildControl = pChildControl->siblings ;
	}
	return ;
}

